package com.example.controller;


import com.example.entity.Mycoupon;
import com.example.service.IMycouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 爪哇岛主
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/mycoupon")
public class MyCouponController {


    @Autowired
    private IMycouponService mycouponService;



    // 查询所有优惠券的接口
    @GetMapping("/all")
    public List<Mycoupon> getAllCoupons() {
        return mycouponService.list();
    }

    // 根据ID查询优惠券的接口
    @GetMapping("/{id}")
    public Mycoupon getCouponById(@PathVariable("id") Integer id) {
        return mycouponService.getById(id);
    }

    // 添加优惠券的接口
    @PostMapping("/add")
    public boolean addCoupon(@RequestBody Mycoupon mycoupon) {
        return mycouponService.save(mycoupon);
    }

    // 更新优惠券的接口
    @PutMapping("/update")
    public boolean updateCoupon(@RequestBody Mycoupon mycoupon) {
        return mycouponService.updateById(mycoupon);
    }

    // 删除优惠券的接口
    @DeleteMapping("/{id}")
    public boolean deleteCoupon(@PathVariable("id") Integer id) {
        return mycouponService.removeById(id);
    }



}
